/* 
 * Copyright (c) 2010 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.enterprise.apis.client;

import com.google.gdata.util.AuthenticationException;

/**
 * Creates an ImprovedGsaClientFactory using the specified parameters 
 *
 */
public class ImprovedGsaClientFactory {
  
  private static final String HTTP_DEFAULT_PROTOCOL = "http";
  private static final int DEFAULT_HTTP_PORT = 8000;

  /**
   * Constructs an instance connecting to the GSA server with address
   * {@code addr}, default port and default protocol.
   * @param addr the address of the GSA server
   * @param userId the name of the user
   * @param userPwd the password of the user
   * @throws AuthenticationException if authentication failed.
   */
  public static ImprovedGsaClient create (String addr, String userId, 
      String userPwd) throws AuthenticationException {
    return create(HTTP_DEFAULT_PROTOCOL, addr, DEFAULT_HTTP_PORT, userId, userPwd);
  }
  
  /**
   * Constructs an instance connecting to the GSA server with address
   * {@code addr}, port {@code port} and default protocol.
   * @param addr the address of the GSA server
   * @param port the port of the GSA server
   * @param userId the name of the user
   * @param userPwd the password of the user
   * @throws AuthenticationException if authentication failed.
   */
  public static ImprovedGsaClient create(String addr, int port, String userId, 
      String userPwd) throws AuthenticationException {
    return create(HTTP_DEFAULT_PROTOCOL, addr, port, userId, userPwd);
  }
  
  /**
   * Constructs an instance connecting to the GSA server with address
   * {@code addr}, port {@code port} and protocol{@code protocol}.
   * @param protocol the protocol of the GSA server
   * @param addr the address of the GSA server
   * @param port the port of the GSA server
   * @param userId the name of the user
   * @param userPwd the password of the user
   * @throws AuthenticationException if authentication failed.
   */
  public static ImprovedGsaClient create(String protocol, String addr, int port, 
      String userId, String userPwd) throws AuthenticationException {
    ImprovedGsaClient client = 
      new ImprovedGsaClient(protocol, addr, port, userId, userPwd);
    
    client.login();
    return client;
  }
  
  // This constructor will never be invoked
  private ImprovedGsaClientFactory() {  }
}
